from yawSrc.tools.loadFile import  toPowerCompressAttrCsv
import pandas as pd
import numpy as np

from common.config import yawConfig as Config

def funMean(x):

    return np.mean(x[Config.ActPower])

def funMax(x):
    return max(x[Config.ActPower])

def df_read_csv(filename, fun, legend):
    X = pd.read_csv(filename)
    X = X.groupby(Config.WindSpeed, as_index=False).apply(lambda x: fun(x))
    X = pd.DataFrame(X)
    X['图例'] = legend
    X.columns = [Config.WindSpeed, Config.ActPower, '图例']
    return X

def powerCompareProcess():
    print('powerCompareProcess 进行中................')

    X = df_read_csv(Config.hisSurfaceProcess, funMean, '历史功率')
    print("X: ", X)
    # X = pd.concat([X, df_read_csv(Config.onlSurfaceProcess, funMax, '拟优化功率')])
    X = pd.concat([X, df_read_csv(Config.onlSurfaceProcess, funMean, '实际优化功率')])
    X = pd.DataFrame(X, columns=[Config.WindSpeed, Config.ActPower, '图例'])
    X.to_csv(Config.powerCompareProcess, index=False)

    toPowerCompressAttrCsv(Config.powerCompareProcess, Config.powerCompareAttr)
    print('powerCompareProcess 结束................')

if __name__ == '__main__':
    powerCompareProcess()








